package com.web.controller;

import com.alibaba.fastjson2.JSON;
import com.web.entity.Book;
import com.web.entity.ResponseResult;
import com.web.service.BookService;
import com.web.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author lenovo
 * @Description
 * @Date2025-3-13 22:13
 */
@WebServlet("/updateBook")
public class UpadteBookServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获得学生信息参数
        String sId = req.getParameter("id");
        String bookname = req.getParameter("bookname");
        String name = req.getParameter("name");
        String price = req.getParameter("price");
        String publishe = req.getParameter("publishe");
        int id = 0;
        if(sId != null){
            id = Integer.parseInt(sId);
        }
        Book book = new Book(id,bookname,name,price,publishe);
        //更新学生
        BookService bookService = new BookServiceImpl();
        bookService.updateBook(book);
        //返回消息
        resp.getWriter().write(JSON.toJSONString(new ResponseResult(200,"OK",null)));
    }
}
